{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2750b4b0",
   "metadata": {},
   "source": [
    "______________\n",
    "\n",
    "* 2022/9/19/week05\n",
    "* Python学习记录"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eecb0729",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 控制流\n",
    ">> 1. 条件判断\n",
    ">> 2. 循环遍历\n",
    "\n",
    "\n",
    "> 2. 随机函数\n",
    "\n",
    "\n",
    "> 3. 时间函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65607555",
   "metadata": {},
   "source": [
    "## 1. 控制流\n",
    "\n",
    "### 1.1 条件判断\n",
    "\n",
    "* 知识点\n",
    "> 1. 赋值 是 “=”\n",
    "> 2. 判断是否两者相等 是 “===”\n",
    "> 3. 代码中出现的变量，必须先定义，否则：name变量名 is not defined"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "31f15ed5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Party!\n"
     ]
    }
   ],
   "source": [
    "# 先定义变量 today\n",
    "\n",
    "today = \"Saturday\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f515c781",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'condition' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mParty!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m today \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSunday\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m----> 6\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mcondition\u001b[49m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mHeadache\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m      7\u001b[0m         \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRecover, then rest.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      8\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n",
      "\u001b[1;31mNameError\u001b[0m: name 'condition' is not defined"
     ]
    }
   ],
   "source": [
    "today = \"Sunday\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "eaeb85f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Recover, then rest.\n"
     ]
    }
   ],
   "source": [
    "today = \"Sunday\"\n",
    "condition = \"Headache\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d30a5f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 关于if else条件判断实践：\n",
    "## 请判断今天是周几，如果是周一，有Python课，好开心呀。如果不是，期待周一呀。（time可以帮我们知道今天周几）\n",
    "##                       如果是周一，请判断现在是否正在上Python课。 （time可以帮助我们知道现在是几点钟几分钟）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "21f69eaa",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1b3ec506",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=19, tm_hour=10, tm_min=27, tm_sec=22, tm_wday=0, tm_yday=262, tm_isdst=0)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f9bf338c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "40a176ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周几 0\n",
      "几点 11\n",
      "几分 6\n"
     ]
    }
   ],
   "source": [
    "#  tm_day  0-6   0 是周一\n",
    "# 准备工作：准备所有可能用到的变量\n",
    "wday = time.localtime().tm_wday\n",
    "print(\"周几\",wday)\n",
    "today_hour = time.localtime().tm_hour\n",
    "print(\"几点\",today_hour)\n",
    "today_min = time.localtime().tm_min\n",
    "print(\"几分\",today_min)\n",
    "# 条件判断，完成：\n",
    "## 关于if else条件判断实践：\n",
    "## 请判断今天是周几，如果是周一，有Python课，好开心呀。如果不是，期待周一呀。（time可以帮我们知道今天周几）\n",
    "##                       如果是周一，请判断现在是否正在上Python课。 （time可以帮助我们知道现在是几点钟几分钟）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "e3c1a43c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周几 0\n",
      "几点 11\n",
      "几分 7\n",
      "今天是周一，有Python课，好开心呀\n",
      "现在是 11 点 7 分 正在上 Python\n"
     ]
    }
   ],
   "source": [
    "wday = time.localtime().tm_wday\n",
    "print(\"周几\",wday)\n",
    "today_hour = time.localtime().tm_hour\n",
    "print(\"几点\",today_hour)\n",
    "today_min = time.localtime().tm_min\n",
    "print(\"几分\",today_min)\n",
    "if wday == 0:\n",
    "    print(\"今天是周一，有Python课，好开心呀\")\n",
    "    if 9 < today_hour < 12:\n",
    "        print(\"现在是\",today_hour,\"点\",today_min,\"分\",\"正在上 Python\")\n",
    "    elif today_hour == 9:\n",
    "        if today_min >= 45:\n",
    "            print(\"正在上 Python\")\n",
    "        elif today_min == 30:\n",
    "            print(\"手机弹出框,还有15分钟要上Python课了，请提前准备好课本和电脑，检查好电量！\")\n",
    "        else:\n",
    "            print(\"马上就要上Python了,好激动呀~\")\n",
    "    else:\n",
    "        print(\"没在上Python\")\n",
    "else:\n",
    "    print(\"期待周一呀\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "85ccb84b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in module time:\n",
      "\n",
      "NAME\n",
      "    time - This module provides various functions to manipulate time values.\n",
      "\n",
      "DESCRIPTION\n",
      "    There are two standard representations of time.  One is the number\n",
      "    of seconds since the Epoch, in UTC (a.k.a. GMT).  It may be an integer\n",
      "    or a floating point number (to represent fractions of seconds).\n",
      "    The Epoch is system-defined; on Unix, it is generally January 1st, 1970.\n",
      "    The actual value can be retrieved by calling gmtime(0).\n",
      "    \n",
      "    The other representation is a tuple of 9 integers giving local time.\n",
      "    The tuple items are:\n",
      "      year (including century, e.g. 1998)\n",
      "      month (1-12)\n",
      "      day (1-31)\n",
      "      hours (0-23)\n",
      "      minutes (0-59)\n",
      "      seconds (0-59)\n",
      "      weekday (0-6, Monday is 0)\n",
      "      Julian day (day in the year, 1-366)\n",
      "      DST (Daylight Savings Time) flag (-1, 0 or 1)\n",
      "    If the DST flag is 0, the time is given in the regular time zone;\n",
      "    if it is 1, the time is given in the DST time zone;\n",
      "    if it is -1, mktime() should guess based on the date and time.\n",
      "\n",
      "CLASSES\n",
      "    builtins.tuple(builtins.object)\n",
      "        struct_time\n",
      "    \n",
      "    class struct_time(builtins.tuple)\n",
      "     |  struct_time(iterable=(), /)\n",
      "     |  \n",
      "     |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      "     |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      "     |  sequence of 9 integers.\n",
      "     |  \n",
      "     |  Note that several fields' values are not the same as those defined by\n",
      "     |  the C language standard for struct tm.  For example, the value of the\n",
      "     |  field tm_year is the actual year, not year - 1900.  See individual\n",
      "     |  fields' descriptions for details.\n",
      "     |  \n",
      "     |  Method resolution order:\n",
      "     |      struct_time\n",
      "     |      builtins.tuple\n",
      "     |      builtins.object\n",
      "     |  \n",
      "     |  Methods defined here:\n",
      "     |  \n",
      "     |  __reduce__(...)\n",
      "     |      Helper for pickle.\n",
      "     |  \n",
      "     |  __repr__(self, /)\n",
      "     |      Return repr(self).\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Static methods defined here:\n",
      "     |  \n",
      "     |  __new__(*args, **kwargs) from builtins.type\n",
      "     |      Create and return a new object.  See help(type) for accurate signature.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data descriptors defined here:\n",
      "     |  \n",
      "     |  tm_gmtoff\n",
      "     |      offset from UTC in seconds\n",
      "     |  \n",
      "     |  tm_hour\n",
      "     |      hours, range [0, 23]\n",
      "     |  \n",
      "     |  tm_isdst\n",
      "     |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      "     |  \n",
      "     |  tm_mday\n",
      "     |      day of month, range [1, 31]\n",
      "     |  \n",
      "     |  tm_min\n",
      "     |      minutes, range [0, 59]\n",
      "     |  \n",
      "     |  tm_mon\n",
      "     |      month of year, range [1, 12]\n",
      "     |  \n",
      "     |  tm_sec\n",
      "     |      seconds, range [0, 61])\n",
      "     |  \n",
      "     |  tm_wday\n",
      "     |      day of week, range [0, 6], Monday is 0\n",
      "     |  \n",
      "     |  tm_yday\n",
      "     |      day of year, range [1, 366]\n",
      "     |  \n",
      "     |  tm_year\n",
      "     |      year, for example, 1993\n",
      "     |  \n",
      "     |  tm_zone\n",
      "     |      abbreviation of timezone name\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data and other attributes defined here:\n",
      "     |  \n",
      "     |  n_fields = 11\n",
      "     |  \n",
      "     |  n_sequence_fields = 9\n",
      "     |  \n",
      "     |  n_unnamed_fields = 0\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from builtins.tuple:\n",
      "     |  \n",
      "     |  __add__(self, value, /)\n",
      "     |      Return self+value.\n",
      "     |  \n",
      "     |  __contains__(self, key, /)\n",
      "     |      Return key in self.\n",
      "     |  \n",
      "     |  __eq__(self, value, /)\n",
      "     |      Return self==value.\n",
      "     |  \n",
      "     |  __ge__(self, value, /)\n",
      "     |      Return self>=value.\n",
      "     |  \n",
      "     |  __getattribute__(self, name, /)\n",
      "     |      Return getattr(self, name).\n",
      "     |  \n",
      "     |  __getitem__(self, key, /)\n",
      "     |      Return self[key].\n",
      "     |  \n",
      "     |  __getnewargs__(self, /)\n",
      "     |  \n",
      "     |  __gt__(self, value, /)\n",
      "     |      Return self>value.\n",
      "     |  \n",
      "     |  __hash__(self, /)\n",
      "     |      Return hash(self).\n",
      "     |  \n",
      "     |  __iter__(self, /)\n",
      "     |      Implement iter(self).\n",
      "     |  \n",
      "     |  __le__(self, value, /)\n",
      "     |      Return self<=value.\n",
      "     |  \n",
      "     |  __len__(self, /)\n",
      "     |      Return len(self).\n",
      "     |  \n",
      "     |  __lt__(self, value, /)\n",
      "     |      Return self<value.\n",
      "     |  \n",
      "     |  __mul__(self, value, /)\n",
      "     |      Return self*value.\n",
      "     |  \n",
      "     |  __ne__(self, value, /)\n",
      "     |      Return self!=value.\n",
      "     |  \n",
      "     |  __rmul__(self, value, /)\n",
      "     |      Return value*self.\n",
      "     |  \n",
      "     |  count(self, value, /)\n",
      "     |      Return number of occurrences of value.\n",
      "     |  \n",
      "     |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      "     |      Return first index of value.\n",
      "     |      \n",
      "     |      Raises ValueError if the value is not present.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Class methods inherited from builtins.tuple:\n",
      "     |  \n",
      "     |  __class_getitem__(...) from builtins.type\n",
      "     |      See PEP 585\n",
      "\n",
      "FUNCTIONS\n",
      "    asctime(...)\n",
      "        asctime([tuple]) -> string\n",
      "        \n",
      "        Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.\n",
      "        When the time tuple is not present, current time as returned by localtime()\n",
      "        is used.\n",
      "    \n",
      "    ctime(...)\n",
      "        ctime(seconds) -> string\n",
      "        \n",
      "        Convert a time in seconds since the Epoch to a string in local time.\n",
      "        This is equivalent to asctime(localtime(seconds)). When the time tuple is\n",
      "        not present, current time as returned by localtime() is used.\n",
      "    \n",
      "    get_clock_info(...)\n",
      "        get_clock_info(name: str) -> dict\n",
      "        \n",
      "        Get information of the specified clock.\n",
      "    \n",
      "    gmtime(...)\n",
      "        gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,\n",
      "                               tm_sec, tm_wday, tm_yday, tm_isdst)\n",
      "        \n",
      "        Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.\n",
      "        GMT).  When 'seconds' is not passed in, convert the current time instead.\n",
      "        \n",
      "        If the platform supports the tm_gmtoff and tm_zone, they are available as\n",
      "        attributes only.\n",
      "    \n",
      "    localtime(...)\n",
      "        localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,\n",
      "                                  tm_sec,tm_wday,tm_yday,tm_isdst)\n",
      "        \n",
      "        Convert seconds since the Epoch to a time tuple expressing local time.\n",
      "        When 'seconds' is not passed in, convert the current time instead.\n",
      "    \n",
      "    mktime(...)\n",
      "        mktime(tuple) -> floating point number\n",
      "        \n",
      "        Convert a time tuple in local time to seconds since the Epoch.\n",
      "        Note that mktime(gmtime(0)) will not generally return zero for most\n",
      "        time zones; instead the returned value will either be equal to that\n",
      "        of the timezone or altzone attributes on the time module.\n",
      "    \n",
      "    monotonic(...)\n",
      "        monotonic() -> float\n",
      "        \n",
      "        Monotonic clock, cannot go backward.\n",
      "    \n",
      "    monotonic_ns(...)\n",
      "        monotonic_ns() -> int\n",
      "        \n",
      "        Monotonic clock, cannot go backward, as nanoseconds.\n",
      "    \n",
      "    perf_counter(...)\n",
      "        perf_counter() -> float\n",
      "        \n",
      "        Performance counter for benchmarking.\n",
      "    \n",
      "    perf_counter_ns(...)\n",
      "        perf_counter_ns() -> int\n",
      "        \n",
      "        Performance counter for benchmarking as nanoseconds.\n",
      "    \n",
      "    process_time(...)\n",
      "        process_time() -> float\n",
      "        \n",
      "        Process time for profiling: sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    process_time_ns(...)\n",
      "        process_time() -> int\n",
      "        \n",
      "        Process time for profiling as nanoseconds:\n",
      "        sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    sleep(...)\n",
      "        sleep(seconds)\n",
      "        \n",
      "        Delay execution for a given number of seconds.  The argument may be\n",
      "        a floating point number for subsecond precision.\n",
      "    \n",
      "    strftime(...)\n",
      "        strftime(format[, tuple]) -> string\n",
      "        \n",
      "        Convert a time tuple to a string according to a format specification.\n",
      "        See the library reference manual for formatting codes. When the time tuple\n",
      "        is not present, current time as returned by localtime() is used.\n",
      "        \n",
      "        Commonly used format codes:\n",
      "        \n",
      "        %Y  Year with century as a decimal number.\n",
      "        %m  Month as a decimal number [01,12].\n",
      "        %d  Day of the month as a decimal number [01,31].\n",
      "        %H  Hour (24-hour clock) as a decimal number [00,23].\n",
      "        %M  Minute as a decimal number [00,59].\n",
      "        %S  Second as a decimal number [00,61].\n",
      "        %z  Time zone offset from UTC.\n",
      "        %a  Locale's abbreviated weekday name.\n",
      "        %A  Locale's full weekday name.\n",
      "        %b  Locale's abbreviated month name.\n",
      "        %B  Locale's full month name.\n",
      "        %c  Locale's appropriate date and time representation.\n",
      "        %I  Hour (12-hour clock) as a decimal number [01,12].\n",
      "        %p  Locale's equivalent of either AM or PM.\n",
      "        \n",
      "        Other codes may be available on your platform.  See documentation for\n",
      "        the C library strftime function.\n",
      "    \n",
      "    strptime(...)\n",
      "        strptime(string, format) -> struct_time\n",
      "        \n",
      "        Parse a string to a time tuple according to a format specification.\n",
      "        See the library reference manual for formatting codes (same as\n",
      "        strftime()).\n",
      "        \n",
      "        Commonly used format codes:\n",
      "        \n",
      "        %Y  Year with century as a decimal number.\n",
      "        %m  Month as a decimal number [01,12].\n",
      "        %d  Day of the month as a decimal number [01,31].\n",
      "        %H  Hour (24-hour clock) as a decimal number [00,23].\n",
      "        %M  Minute as a decimal number [00,59].\n",
      "        %S  Second as a decimal number [00,61].\n",
      "        %z  Time zone offset from UTC.\n",
      "        %a  Locale's abbreviated weekday name.\n",
      "        %A  Locale's full weekday name.\n",
      "        %b  Locale's abbreviated month name.\n",
      "        %B  Locale's full month name.\n",
      "        %c  Locale's appropriate date and time representation.\n",
      "        %I  Hour (12-hour clock) as a decimal number [01,12].\n",
      "        %p  Locale's equivalent of either AM or PM.\n",
      "        \n",
      "        Other codes may be available on your platform.  See documentation for\n",
      "        the C library strftime function.\n",
      "    \n",
      "    thread_time(...)\n",
      "        thread_time() -> float\n",
      "        \n",
      "        Thread time for profiling: sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    thread_time_ns(...)\n",
      "        thread_time() -> int\n",
      "        \n",
      "        Thread time for profiling as nanoseconds:\n",
      "        sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    time(...)\n",
      "        time() -> floating point number\n",
      "        \n",
      "        Return the current time in seconds since the Epoch.\n",
      "        Fractions of a second may be present if the system clock provides them.\n",
      "    \n",
      "    time_ns(...)\n",
      "        time_ns() -> int\n",
      "        \n",
      "        Return the current time in nanoseconds since the Epoch.\n",
      "\n",
      "DATA\n",
      "    altzone = -32400\n",
      "    daylight = 0\n",
      "    timezone = -28800\n",
      "    tzname = ('中国标准时间', '中国夏令时')\n",
      "\n",
      "FILE\n",
      "    (built-in)\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2926ff1",
   "metadata": {},
   "source": [
    "## 2. 循环遍历（for)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "1e886529",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "719c206e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f2973a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 上述 i  和 ch  都是变量，可以根据我们的需求定义变量名\n",
    "# 每一次执行，赋值一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "0e33e272",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n",
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "# range(): 范围，区间\n",
    "for num in range(10):\n",
    "    print('hello world!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "731d30d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for num in range(10):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "13179fbd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# range() 是一个数字/数值生成器，默认每次增加1\n",
    " \n",
    "# range() 包含有   起始点start(默认为0)      终止点 stop    以及步长step(默认为1)\n",
    "range(5)  # 默认的起点 是  0   ，终结点   5         产生了   5 - 0 个数值，默认每次增加1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "f3d21476",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "0a9917f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(5, 10)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5,10)   # 自定义起始点     5， 终结点   10    产生了    10 - 5个数值，默认每次增加1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "298f1ea2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "73e19baa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 10, 3)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0,10,3)   #自定义起始点     0， 终结点   10    自定义每次增加3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "1e23a967",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 9]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5591c66a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 请参考以下，获取广州南方学院"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "ee0547f1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/tzgg/index0.htm\n",
      "https://www.nfu.edu.cn/tzgg/index1.htm\n",
      "https://www.nfu.edu.cn/tzgg/index2.htm\n",
      "https://www.nfu.edu.cn/tzgg/index3.htm\n",
      "https://www.nfu.edu.cn/tzgg/index4.htm\n",
      "https://www.nfu.edu.cn/tzgg/index5.htm\n",
      "https://www.nfu.edu.cn/tzgg/index6.htm\n",
      "https://www.nfu.edu.cn/tzgg/index7.htm\n",
      "https://www.nfu.edu.cn/tzgg/index8.htm\n",
      "https://www.nfu.edu.cn/tzgg/index9.htm\n",
      "https://www.nfu.edu.cn/tzgg/index10.htm\n",
      "https://www.nfu.edu.cn/tzgg/index11.htm\n",
      "https://www.nfu.edu.cn/tzgg/index12.htm\n",
      "https://www.nfu.edu.cn/tzgg/index13.htm\n",
      "https://www.nfu.edu.cn/tzgg/index14.htm\n",
      "https://www.nfu.edu.cn/tzgg/index15.htm\n",
      "https://www.nfu.edu.cn/tzgg/index16.htm\n",
      "https://www.nfu.edu.cn/tzgg/index17.htm\n",
      "https://www.nfu.edu.cn/tzgg/index18.htm\n",
      "https://www.nfu.edu.cn/tzgg/index19.htm\n",
      "https://www.nfu.edu.cn/tzgg/index20.htm\n",
      "https://www.nfu.edu.cn/tzgg/index21.htm\n",
      "https://www.nfu.edu.cn/tzgg/index22.htm\n",
      "https://www.nfu.edu.cn/tzgg/index23.htm\n",
      "https://www.nfu.edu.cn/tzgg/index24.htm\n",
      "https://www.nfu.edu.cn/tzgg/index25.htm\n",
      "https://www.nfu.edu.cn/tzgg/index26.htm\n",
      "https://www.nfu.edu.cn/tzgg/index27.htm\n",
      "https://www.nfu.edu.cn/tzgg/index28.htm\n",
      "https://www.nfu.edu.cn/tzgg/index29.htm\n",
      "https://www.nfu.edu.cn/tzgg/index30.htm\n",
      "https://www.nfu.edu.cn/tzgg/index31.htm\n",
      "https://www.nfu.edu.cn/tzgg/index32.htm\n",
      "https://www.nfu.edu.cn/tzgg/index33.htm\n",
      "https://www.nfu.edu.cn/tzgg/index34.htm\n",
      "https://www.nfu.edu.cn/tzgg/index35.htm\n",
      "https://www.nfu.edu.cn/tzgg/index36.htm\n"
     ]
    }
   ],
   "source": [
    "# 实践：  数据挖掘---获取页面URL队列\n",
    "学校要闻 = \"xxyw\"\n",
    "学校要闻_page = 110\n",
    "通知公告 = \"tzgg\"\n",
    "\n",
    "for page in range(37):\n",
    "    print(\"https://www.nfu.edu.cn/tzgg/index\" + str(page) + \".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d4216d15",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '学校要闻' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m 学校要闻_page \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m110\u001b[39m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m page \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m110\u001b[39m):\n\u001b[1;32m----> 4\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://www.nfu.edu.cn/\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m+\u001b[39m\u001b[43m学校要闻\u001b[49m\u001b[38;5;241m+\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/index\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mstr\u001b[39m(page) \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.htm\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name '学校要闻' is not defined"
     ]
    }
   ],
   "source": [
    "学校要闻_page = 110\n",
    "\n",
    "for page in range(110):\n",
    "    print(\"https://www.nfu.edu.cn/\"+学校要闻+\"/index\" + str(page) + \".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b6f0dce9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/xxyw/index0.htm\n",
      "https://www.nfu.edu.cn/xxyw/index1.htm\n",
      "https://www.nfu.edu.cn/xxyw/index2.htm\n",
      "https://www.nfu.edu.cn/xxyw/index3.htm\n",
      "https://www.nfu.edu.cn/xxyw/index4.htm\n",
      "https://www.nfu.edu.cn/xxyw/index5.htm\n",
      "https://www.nfu.edu.cn/xxyw/index6.htm\n",
      "https://www.nfu.edu.cn/xxyw/index7.htm\n",
      "https://www.nfu.edu.cn/xxyw/index8.htm\n",
      "https://www.nfu.edu.cn/xxyw/index9.htm\n",
      "https://www.nfu.edu.cn/xxyw/index10.htm\n",
      "https://www.nfu.edu.cn/xxyw/index11.htm\n",
      "https://www.nfu.edu.cn/xxyw/index12.htm\n",
      "https://www.nfu.edu.cn/xxyw/index13.htm\n",
      "https://www.nfu.edu.cn/xxyw/index14.htm\n",
      "https://www.nfu.edu.cn/xxyw/index15.htm\n",
      "https://www.nfu.edu.cn/xxyw/index16.htm\n",
      "https://www.nfu.edu.cn/xxyw/index17.htm\n",
      "https://www.nfu.edu.cn/xxyw/index18.htm\n",
      "https://www.nfu.edu.cn/xxyw/index19.htm\n",
      "https://www.nfu.edu.cn/xxyw/index20.htm\n",
      "https://www.nfu.edu.cn/xxyw/index21.htm\n",
      "https://www.nfu.edu.cn/xxyw/index22.htm\n",
      "https://www.nfu.edu.cn/xxyw/index23.htm\n",
      "https://www.nfu.edu.cn/xxyw/index24.htm\n",
      "https://www.nfu.edu.cn/xxyw/index25.htm\n",
      "https://www.nfu.edu.cn/xxyw/index26.htm\n",
      "https://www.nfu.edu.cn/xxyw/index27.htm\n",
      "https://www.nfu.edu.cn/xxyw/index28.htm\n",
      "https://www.nfu.edu.cn/xxyw/index29.htm\n",
      "https://www.nfu.edu.cn/xxyw/index30.htm\n",
      "https://www.nfu.edu.cn/xxyw/index31.htm\n",
      "https://www.nfu.edu.cn/xxyw/index32.htm\n",
      "https://www.nfu.edu.cn/xxyw/index33.htm\n",
      "https://www.nfu.edu.cn/xxyw/index34.htm\n",
      "https://www.nfu.edu.cn/xxyw/index35.htm\n",
      "https://www.nfu.edu.cn/xxyw/index36.htm\n",
      "https://www.nfu.edu.cn/xxyw/index37.htm\n",
      "https://www.nfu.edu.cn/xxyw/index38.htm\n",
      "https://www.nfu.edu.cn/xxyw/index39.htm\n",
      "https://www.nfu.edu.cn/xxyw/index40.htm\n",
      "https://www.nfu.edu.cn/xxyw/index41.htm\n",
      "https://www.nfu.edu.cn/xxyw/index42.htm\n",
      "https://www.nfu.edu.cn/xxyw/index43.htm\n",
      "https://www.nfu.edu.cn/xxyw/index44.htm\n",
      "https://www.nfu.edu.cn/xxyw/index45.htm\n",
      "https://www.nfu.edu.cn/xxyw/index46.htm\n",
      "https://www.nfu.edu.cn/xxyw/index47.htm\n",
      "https://www.nfu.edu.cn/xxyw/index48.htm\n",
      "https://www.nfu.edu.cn/xxyw/index49.htm\n",
      "https://www.nfu.edu.cn/xxyw/index50.htm\n",
      "https://www.nfu.edu.cn/xxyw/index51.htm\n",
      "https://www.nfu.edu.cn/xxyw/index52.htm\n",
      "https://www.nfu.edu.cn/xxyw/index53.htm\n",
      "https://www.nfu.edu.cn/xxyw/index54.htm\n",
      "https://www.nfu.edu.cn/xxyw/index55.htm\n",
      "https://www.nfu.edu.cn/xxyw/index56.htm\n",
      "https://www.nfu.edu.cn/xxyw/index57.htm\n",
      "https://www.nfu.edu.cn/xxyw/index58.htm\n",
      "https://www.nfu.edu.cn/xxyw/index59.htm\n",
      "https://www.nfu.edu.cn/xxyw/index60.htm\n",
      "https://www.nfu.edu.cn/xxyw/index61.htm\n",
      "https://www.nfu.edu.cn/xxyw/index62.htm\n",
      "https://www.nfu.edu.cn/xxyw/index63.htm\n",
      "https://www.nfu.edu.cn/xxyw/index64.htm\n",
      "https://www.nfu.edu.cn/xxyw/index65.htm\n",
      "https://www.nfu.edu.cn/xxyw/index66.htm\n",
      "https://www.nfu.edu.cn/xxyw/index67.htm\n",
      "https://www.nfu.edu.cn/xxyw/index68.htm\n",
      "https://www.nfu.edu.cn/xxyw/index69.htm\n",
      "https://www.nfu.edu.cn/xxyw/index70.htm\n",
      "https://www.nfu.edu.cn/xxyw/index71.htm\n",
      "https://www.nfu.edu.cn/xxyw/index72.htm\n",
      "https://www.nfu.edu.cn/xxyw/index73.htm\n",
      "https://www.nfu.edu.cn/xxyw/index74.htm\n",
      "https://www.nfu.edu.cn/xxyw/index75.htm\n",
      "https://www.nfu.edu.cn/xxyw/index76.htm\n",
      "https://www.nfu.edu.cn/xxyw/index77.htm\n",
      "https://www.nfu.edu.cn/xxyw/index78.htm\n",
      "https://www.nfu.edu.cn/xxyw/index79.htm\n",
      "https://www.nfu.edu.cn/xxyw/index80.htm\n",
      "https://www.nfu.edu.cn/xxyw/index81.htm\n",
      "https://www.nfu.edu.cn/xxyw/index82.htm\n",
      "https://www.nfu.edu.cn/xxyw/index83.htm\n",
      "https://www.nfu.edu.cn/xxyw/index84.htm\n",
      "https://www.nfu.edu.cn/xxyw/index85.htm\n",
      "https://www.nfu.edu.cn/xxyw/index86.htm\n",
      "https://www.nfu.edu.cn/xxyw/index87.htm\n",
      "https://www.nfu.edu.cn/xxyw/index88.htm\n",
      "https://www.nfu.edu.cn/xxyw/index89.htm\n",
      "https://www.nfu.edu.cn/xxyw/index90.htm\n",
      "https://www.nfu.edu.cn/xxyw/index91.htm\n",
      "https://www.nfu.edu.cn/xxyw/index92.htm\n",
      "https://www.nfu.edu.cn/xxyw/index93.htm\n",
      "https://www.nfu.edu.cn/xxyw/index94.htm\n",
      "https://www.nfu.edu.cn/xxyw/index95.htm\n",
      "https://www.nfu.edu.cn/xxyw/index96.htm\n",
      "https://www.nfu.edu.cn/xxyw/index97.htm\n",
      "https://www.nfu.edu.cn/xxyw/index98.htm\n",
      "https://www.nfu.edu.cn/xxyw/index99.htm\n",
      "https://www.nfu.edu.cn/xxyw/index100.htm\n",
      "https://www.nfu.edu.cn/xxyw/index101.htm\n",
      "https://www.nfu.edu.cn/xxyw/index102.htm\n",
      "https://www.nfu.edu.cn/xxyw/index103.htm\n",
      "https://www.nfu.edu.cn/xxyw/index104.htm\n",
      "https://www.nfu.edu.cn/xxyw/index105.htm\n",
      "https://www.nfu.edu.cn/xxyw/index106.htm\n",
      "https://www.nfu.edu.cn/xxyw/index107.htm\n",
      "https://www.nfu.edu.cn/xxyw/index108.htm\n",
      "https://www.nfu.edu.cn/xxyw/index109.htm\n"
     ]
    }
   ],
   "source": [
    "for page in range(110):\n",
    "    print(\"https://www.nfu.edu.cn/xxyw/index\" + str(page) + \".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4cbd7075",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
